﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>支票登记</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    
    <!--liyu 添加jquery easy ui 控件 begin-->
    <script type="text/javascript" src="../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../Scripts/themes/icon.css">
    <!--liyu 添加jquery easy ui 控件 end-->

    <script type="text/javascript" src="../Scripts/banBackSpace.js"></script>
    <script type="text/javascript">
        var detailPanel, currentUID, currentGIndex = -1, mode, detailForm, validatorForm, submitForm, showDetialForm, rowData, goOn = true;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [], comboxStatusData = [], showToolBar;

        $(document).ready(function () {
            currentUID = art.dialog.data('currentUID');
            currentGIndex = art.dialog.data('Index');
            rowData = art.dialog.data('RowData');
            mode = art.dialog.data('Mode');
            detailForm = $('#viewForm');
            $(":input", detailForm).change(function () { detailForm.data('changed', true); });
            showToolBar(detailForm);
            $.ajax({
                cache: false, async: false,
                url: '../Handler/combox.ashx?view=vBaseData',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载相关基础信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxBankData = [], comboxTypeData = [], comboxStatusData = []
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '支票银行':
                                comboxBankData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            case '支票额度':
                                comboxTypeData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            case '支票状态':
                                comboxStatusData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.waiting("close");
                    $.omMessageBox.alert({
                        content: '发现错误<BR>：' + result.status
                    });
                }
            });
            
//          liyu begin 修改银行的下拉框 
            $('#Bank', detailForm).combobox({
                data: comboxBankData,
                valueField: 'name',
                textField: 'name',
                editable: false
            });

//            $('#Bank', detailForm).omCombo({
//                dataSource: comboxBankData,
//                valueField: 'name',
//                optionField: 'name',
//                inputField: 'name'
//            });
//          liyu end

//          liyu begin 修改状态的下拉框
            $('#CheckStatus', detailForm).combobox({
                data: comboxStatusData,
                valueField: 'code',
                textField: 'name',
                disabled: true,
                editable: false
            });             

//            $('#CheckStatus', detailForm).omCombo({
//                dataSource: comboxStatusData,
//                valueField: 'code',
//                optionField: 'name',
//                disabled: true,
//                inputField: 'name'
//            });
//          liyu end    

//          liyu begin 修改类型的下拉框
            $('#CheckType', detailForm).combobox({
                data: comboxTypeData,
                valueField: 'code',
                textField: 'name',
                editable: false
            });

//            $('#CheckType', detailForm).omCombo({
//                dataSource: comboxTypeData,
//                valueField: 'code',
//                optionField: 'name',
//                inputField: 'name'
//            });
//          liyu end 

//            liyu 日期注释  
//            $("#PurchaseDate", detailForm).omCalendar();

            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    CheckNo: { required: true },
                    Bank: { required: true },
                    CheckType: { required: true },
                    PurchaseDate: { required: true },
                    Amount: { number: true }
                },
                messages: {
                    CheckNo: { required: "[支票号码]不能为空" },
                    Bank: { required: "[支票银行]不能为空" },
                    CheckType: { required: "[支票额度]不能为空" },
                    PurchaseDate: { required: "[购买时间]不能为空" },
                    Amount: { number: "金额必须是数字" }
                }
            });
            showDetialForm("数据明细", rowData);
            switch (mode) {
                case 'new':
                    $('#UID', detailForm).val("0");
                    $('#CheckNo', detailForm).val("");
                    $('#Note', detailForm).val("");
                    $('#CheckStatus', detailForm).omCombo("value", 1);
                    $('#CheckType', detailForm).omCombo("value", 1);

//                  liyu begin 日期格式 
                    $('#PurchaseDate').datebox("setValue", new Date().Format("yyyy-MM-dd"));
//                    $('#PurchaseDate', detailForm).val((new Date()).Format("yyyy-MM-dd"));
//                  liyu end                   
                    $('span#button-saveadd', detailForm).omButton('enable');
                    $('#CheckNo', detailForm).focus();
                    break;
                case 'copy':
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $('#UID', detailForm).val("0");
                    $("#CheckNo", detailForm).focus();
                    break;
                case 'update':
                    $('#CheckNo', detailForm).attr("readonly", true);
                    $('span#button-saveadd', detailForm).omButton('disable');
                    $("#CheckNo", detailForm).focus();
                    break;
            }
        });
        showToolBar = function (form) {
            $('span#button-save', form).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateCheck");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddCheck");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#CheckNo", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '支票登记成功',
                                        onClose: function () {
                                            art.dialog.close();
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-saveadd', form).omButton({
                icons: { left: '../Content/Images/List/ok.gif' }, width: 80,
                onClick: function () {
                    if (!detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '表单数据没有更改无需保存'
                        });
                    }
                    else {
                        if (validatorForm.form()) {
                            if (mode == 'update' && $("#UID").val() != "0") {
                                detailForm.attr("action", actionRoot + "&method=UpdateCheck");
                            }
                            else {
                                detailForm.attr("action", actionRoot + "&method=AddCheck");
                            }
                            submitForm(detailForm, function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        type: 'error',
                                        content: '发现错误<BR>：' + data.Message,
                                        onClose: function () {
                                            $("#CheckNo", detailForm).focus();
                                        }
                                    });
                                }
                                else {
                                    $.omMessageBox.alert({
                                        type: 'success',
                                        content: '支票登记成功',
                                        onClose: function () {
                                            $('#UID', detailForm).val("0");
                                            $('#CheckNo', detailForm).val("");
                                            $('#Note', detailForm).val("");
                                            $('#CheckStatus', detailForm).omCombo("value", 1);
                                            $('#CheckType', detailForm).omCombo("value", 1);
//                                          liyu begin 日期格式修改
                                            $('#PurchaseDate').datebox("setValue", new Date().Format("yyyy-MM-dd"));
//                                            $('#PurchaseDate', detailForm).val((new Date()).Format("yyyy-MM-dd"));
//                                          liyu end
                                            $('span#button-saveadd', detailForm).omButton('enable');
                                            $('#CheckNo', detailForm).focus();
                                        }
                                    })
                                }
                            });
                        }
                    }

                }
            });
            $('span#button-cancel', form).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    art.dialog.close();
                }
            });
        }

        showDetialForm = function (title, rowData) {
            if (detailPanel) {
                $("input[type=text]", detailPanel).val("");
                detailPanel.omPanel("open");
            }
            else {
                detailPanel = $('#detail-form').omPanel({
                    width: 'fit',
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>" + title + "</span>",
                    collapsed: false,
                    collapsible: false,
                    closable: false
                });
            }
            validatorForm.resetForm();
            rowData = rowData || {};
            $.each(rowData, function (n, value) {
                if (n == 'PurchaseDate') 
                    {
//                    liyu begin 修改日期控件  
//                    $("input[id='" + n + "']", detailPanel).val(value == null ? '' : new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd"));               
                        $("input[id='" + n + "']", detailPanel).datebox("setValue", new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd"));
//                    liyu end                       
                    }
                else {
                    if (n == 'Bank' || n == 'CheckStatus' || n == 'CheckType') {
//                    liyu begin 下拉框赋值  
//                        $('#' + n, detailForm).omCombo("value", value);
                        $('#' + n).combobox('setValue', value);
//                    liyu end   
                    }
                    else {
//                      liyu begin 多行文本框赋值                        
//                        $("input[id='" + n + "']", detailPanel).val(value);
                        if (n == 'Note') {
                            $("textarea[id='" + n + "']", detailPanel).val(value);
                        }
                        else {
                            $("input[id='" + n + "']", detailPanel).val(value);
                        }

                    }
                }
            })
        };

        submitForm = function (mainform, success, error) {
            if (!mainform)
                return false;
            else {
                mainform.ajaxSubmit({
                    type: "POST",
                    dataType: 'json',
                    success: success,
                    clearForm: false,
                    beforeSubmit: function (formData, jqForm, options) {
                        $(":checkbox,:radio", jqForm).each(function () {
                            if (!existInFormData(formData, this.name)) {
                                formData.push({ name: this.name, type: this.type, value: this.checked });
                            }
                        });
                        for (var i = 0, l = formData.length; i < l; i++) {
                            var o = formData[i];
                            if (o.type == "checkbox" || o.type == "radio") {
                                o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                            }
                        }
                    },
                    beforeSend: function (a, b, c) {
                        $.omMessageBox.waiting({
                            title: '正在保存数据中...',
                            content: '服务器正在处理请求......'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close")
                    },
                    error: function (result) {
                        $.omMessageBox.waiting("close")
                        $.omMessageBox.alert({
                            content: '发现系统错误 <BR>错误码：' + result.status
                        });
                    }
                });
            }
        }

        function existInFormData(formData, name) {
            for (var i = 0, l = formData.length; i < l; i++) {
                var o = formData[i];
                if (o.name == name) return true;
            }
            return false;
        }
    </script>
</head>
<body>
    <div id="detail-form">
        <form id="viewForm">
            <div id="errorMessages" class="error">
            </div>
            <table>
                <tr style="display: none;">
                    <td colspan="6">
                        <input name="UID" id="UID" value="0" />
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 50px; color: red;">支票银行
                    </td>
                    <td align="left" style="width: 120px">
                        <%--<input type="text" class="input-text" name="Bank" id="Bank" style="width: 100%;" />--%>
                       <input class="easyui-combobox" id="Bank" name="Bank" style="width: 120px;"/>
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">支票号码
                    </td>
                    <td align="left" style="width: 120px">
                        <%--<input type="text" class="input-text" name="CheckNo" id="CheckNo" value="" style="width: 100%;" maxlength="8" />--%>
                        <input type="text" class="input-text" name="CheckNo" id="CheckNo" maxlength="8"
                            data-options="required:false;validType:'length[1,8]'" style="border: 1px solid #A4BED4; height:20px;width: 118px;" />
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px;">支票状态
                    </td>
                    <td align="left" style="width: 120px">
                       <%-- <input type="text" class="input-text" name="CheckStatus" id="CheckStatus" style="width: 100%;" />--%>
                        <input class="easyui-combobox" id="CheckStatus" name="CheckStatus" style="width: 120px;"/>
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 50px; color: red;">
                        购买时间
                    </td>
                    <td align="left" style="width: 120px">
                      <%--  <input type="text" class="input-text" name="PurchaseDate" id="PurchaseDate" style="width: 100%;" />--%>
                        <input type="text" class="easyui-datebox" id="PurchaseDate" " name="PurchaseDate" style="width: 120px;" />
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px; color: red;">
                        支票额度
                    </td>
                    <td align="left" style="width: 120px">
                       <%-- <input type="text" class="input-text" name="CheckType" id="CheckType" value="" style="width: 100%;" />--%>
                        <input  class="easyui-combobox" name="CheckType" id="CheckType" style="width: 120px;" />
                    </td>
                    <td align="right" style="width: 80px; margin-left: 10px;">金&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp额
                    </td>
                    <td align="left" style="width: 120px" colspan="2">
                        <%--<input type="text" class="input-text" name="Amount" id="Amount" style="width: 100%;" value="0" />--%>
                        <input class="easyui-numberbox" name="Amount" id="Amount" 
                            style="border: 1px solid #A4BED4;height:20px;width: 118px;" data-options="precision:2,groupSeparator:','" />
                    </td>
                </tr>
                <tr>
                    <td align="right" style="width: 80px; color: red;">备&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp注
                    </td>
                    <td align="left" style="width: 560px" colspan="6">
                        <textarea name="Note" id="Note" style="overflow: auto; border: 1px solid #A4BED4; width: 565px; height: 80px;"></textarea>

                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="6">
                        <span id="button-saveadd">保存新增</span> 
                        <span id="button-save">保&nbsp&nbsp存</span> 
                        <span id="button-cancel">取&nbsp&nbsp消</span>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</body>
</html>
